package org.yun.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.yun.demo.service.StudentAsyncService;
import org.yun.demo.service.dto.StudentDTO;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Created with IDEA
 * author:yunxf
 * Date:2019/9/7
 * Time:2:42 PM
 */
@RestController
public class DemoController {


    @Resource
    StudentAsyncService studentAsyncService;

    @RequestMapping(path = "getname",method = RequestMethod.GET)
    public String getName(){
        return studentAsyncService.getStudentName();
    }

    @GetMapping(path = "/getasyncname")
    public String getAsyncName() throws ExecutionException, InterruptedException {
        return studentAsyncService.getName().get();
    }


    public String getAllNameService(){
        CompletableFuture<String> sleepName = studentAsyncService.getName();
        CompletableFuture<StudentDTO> noSleepName = studentAsyncService.getStudentDto();
//        CompletableFuture<Object> future = CompletableFuture.allOf(sleepName,noSleepName);
        return null;
    }
}
